
//
// 130316 - AH - Created.
//

package org.japril.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.japril.gim.Items;
import org.japril.servlet.httpannotations.HttpProtocolFactory;

/**
 * <p>
 *   TODO
 * </p>
 * @author Arne Halvorsen (AH)
 */
@SuppressWarnings("serial")
public class ProtocolHttpServlet extends HttpServlet
{
  private HttpProtocolDef m_protocol=null;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public ProtocolHttpServlet(){}
  
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
  {
    apiDesc(resp);  
  }
  
  private void apiDesc(HttpServletResponse resp) throws IOException
  {
    resp.setContentType("text/html");
    PrintWriter pw=resp.getWriter();
   
    if (m_protocol==null)
    {
      pw.println("<html><body>");
      pw.println("<p>No Protocol</p>");
      pw.println("</body></html>");
    }
    else
    {
      pw.println(m_protocol.compileApiHtml());
    }
  }

  // Specified in GenericServlet.
  public void init() throws ServletException 
  {
    ServletConfig sc=getServletConfig();
    
    // TODO code to get protocol from parameters, now just makes one for
    // when developing.
    m_protocol=new HttpProtocolFactory().create(Items.class);
  }
  
  
}
